<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>职工资料管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/resources/css/public.css" media="all"/>
    <link rel="stylesheet" href="/resources/layui_ext/dtree/dtree.css" media="all"/>
    <link rel="stylesheet" href="/resources/layui_ext/dtree/font/dtreefont.css" media="all"/>

</head>
<body class="childrenBody">
<!-- 查询条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 5px;">
    <legend>查询条件</legend>
</fieldset>
<blockquote class="layui-elem-quote">
    <form action="" method="post" id="searchFrm" lay-filter="searchFrm" class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">所属医院</label>
                <div class="layui-input-inline">
                    <select name="hospitalId" id="search_hospital_id" lay-filter="search_hospital_id">
                        <option value=""></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">职工类型</label>
                <div class="layui-input-inline">
                    <select name="type">
                        <option value=""></option>
                        <option value="2">医生</option>
                        <option value="3">洗美师</option>
                    </select>
                </div>
            </div>

        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="doSearch"><span
                        class="layui-icon layui-icon-search"></span>查询
                </button>
                <button type="reset" class="layui-btn layui-btn-warm"><span
                        class="layui-icon layui-icon-refresh-1"></span>重置
                </button>
            </div>
        </div>
    </form>
</blockquote>
<!-- 查询条件结束-->


<!-- 数据表格开始 -->
<div>
    <table class="layui-hide" id="userTable" lay-filter="userTable"></table>
    <div id="userToolBar" style="display: none;">
        <button type="button" lay-event="add" class="layui-btn layui-btn-sm"><span
                class="layui-icon layui-icon-add-1"></span>添加职工
        </button>
    </div>

    <div id="userRowBar" style="display: none;">
        <button type="button" lay-event="update" class="layui-btn layui-btn-sm"><span
                class="layui-icon layui-icon-edit"></span>更新
        </button>
        <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger"><span
                class="layui-icon layui-icon-delete"></span>删除
        </button>
        <button type="button" lay-event="resetPwd" class="layui-btn layui-btn-sm"><span
                class="layui-icon layui-icon-edit"></span>重置密码
        </button>
        <button type="button" lay-event="selectRole" class="layui-btn layui-btn-sm layui-btn-danger"><span
                class="layui-icon layui-icon-delete"></span>分配角色
        </button>
    </div>
</div>

<!-- 数据表格结束 -->

<!-- 添加和修改的弹出层开始 -->
<div style="display: none;padding: 5px" id="addOrUpdateDiv">
    <form action="" method="post" class="layui-form layui-form-pane" id="dataFrm" lay-filter="dataFrm">

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">职工姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" id="username" lay-verify="required" autocomplete="off"
                           placeholder="请输入职工姓名" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">工号</label>
                <div class="layui-input-inline">
                    <input type="text" name="jobNumber" id="jobNumber" lay-verify="required" autocomplete="off"
                           placeholder="请输入工号" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">登陆名</label>
                <div class="layui-input-inline">
                    <input type="text" name="loginname" id="loginname" lay-verify="required" autocomplete="off"
                           placeholder="请输入登陆名" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">年龄</label>
                <div class="layui-input-inline">
                    <input type="text" name="age" id="age" lay-verify="required" autocomplete="off"
                           placeholder="请输入年龄" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">身份证号</label>
                <div class="layui-input-inline">
                    <input type="text" name="idNumber" id="idNumber" lay-verify="required" autocomplete="off"
                           placeholder="请输入身份证号" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">联系方式</label>
                <div class="layui-input-inline">
                    <input type="text" name="phone" id="phone" lay-verify="required" autocomplete="off"
                           placeholder="请输入联系方式" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">职位</label>
                <div class="layui-input-inline">
                    <input type="text" name="position" id="position" lay-verify="required" autocomplete="off"
                           placeholder="请输入职位" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-inline">
                    <select name="sex" lay-verify="required">
                        <option value=""></option>
                        <option value="男">男</option>
                        <option value="女">女</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <select name="status" lay-verify="required">
                        <option value=""></option>
                        <option value="当值">当值</option>
                        <option value="未当值">未当值</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">职工类型</label>
                <div class="layui-input-inline">
                    <select name="type">
                        <option value=""></option>
                        <option value="2">医生</option>
                        <option value="3">洗美师</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">所属医院</label>
                <div class="layui-input-inline">
                    <select name="hospitalId" id="search_hospital_id2" lay-filter="search_hospital_id2">
                        <option value=""></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item" id="area-picker">
            <label class="layui-form-label">职工地址</label>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="province" class="province-selector" data-value="广东省" lay-filter="province-1">
                    <option value="">请选择省</option>
                </select>
            </div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="city" class="city-selector" data-value="深圳市" lay-filter="city-1">
                    <option value="">请选择市</option>
                </select>
            </div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="county" class="county-selector" data-value="龙岗区" lay-filter="county-1">
                    <option value="">请选择区</option>
                </select>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">详细地址</label>
            <div class="layui-input-block">
                <input type="text" name="detailAddress" autocomplete="off" placeholder="请输入详细地址" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">职工描述</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" name="description" id="content"></textarea>
            </div>
        </div>
        <div class="layui-form-item">

        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="doSubmit" id="doSubmit"><span
                        class="layui-icon layui-icon-add-1"></span>提交
                </button>
                <button type="reset" class="layui-btn layui-btn-warm">
                    <span class="layui-icon layui-icon-refresh-1"></span>重置
                </button>
            </div>
        </div>
    </form>
</div>
<!-- 添加和修改的弹出层结束 -->


<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript" src="/resources/js/layarea.js"></script>
<script type="text/javascript">
    var tableIns;
    layui.config({
        base: '/resources/js/',
        version: '1.0'
    })
    layui.use(['jquery', 'form', 'table', 'layer', 'layarea'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        var layer = layui.layer;
        var layarea = layui.layarea;
        layarea.render({
            elem: '#area-picker'
        });

        //加载 数据
        tableIns = table.render({
            elem: '#userTable'
            , url: '/user/loadAllEmployee'
            , toolbar: '#userToolBar' //开启头部工具栏，并为其绑定左侧模板
            , title: '职工数据表'
            , height: 'full-250'
            , page: true
            , cols: [
                [
                    {field: 'id', title: 'ID', align: 'center', width: '80'}
                    , {field: 'jobNumber', title: '工号', align: 'center', width: '80'}
                    , {field: 'name', title: '姓名', align: 'center', width: '100'}
                    , {field: 'loginname', title: '登陆名', align: 'center', width: '100'}
                    , {field: 'sex', title: '性别', align: 'center', width: '80'}
                    , {field: 'age', title: '年龄', align: 'center', width: '120'}
                    , {field: 'idNumber', title: '身份证号', align: 'center', width: '100'}
                    , {
                    field: 'type', title: '职工类型', align: 'center', width: '150', templet: function (d) {
                        return d.type == 2 ? '医生' : '洗美师';
                    }
                }
                    , {field: 'phone', title: '手机号码', align: 'center', width: '150'}
                    , {field: 'status', title: '状态', align: 'center', width: '150'}
                    , {field: 'fullAddress', title: '家庭住址', align: 'center', width: '150'}
                    , {
                    field: 'available', title: '是否可用', align: 'center', width: '100', templet: function (d) {
                        return d.available == 1 ? '<font color=blue>可用</font>' : '<font color=red>不可用</font>';
                    }
                }
                    , {fixed: 'right', title: '操作', toolbar: '#userRowBar', align: 'center', width: '400'}
                ]
            ]
            , done: function (res, curr, count) { //处理删除某一页最后一条数据的BUG
                if (res.data.length == 0 && curr != 1) {
                    tableIns.reload({
                        page: {
                            curr: (curr - 1)
                        }
                    });
                }
            }
        });

        //加载查询条件医院的下拉列表
        $.get("/hospital/loadAllHospitalForSelect", function (res) {
            var data = res.data;
            var dom = $("#search_hospital_id");
            var html = '<option value="0">请选择医院</option>'
            $.each(data, function (index, item) {
                html += '<option value="' + item.id + '">' + item.name + '</option>'
            });
            dom.html(html);
            form.render("select");
        });
        $.get("/hospital/loadAllHospitalForSelect", function (res) {
            var data = res.data;
            var dom = $("#search_hospital_id2");
            var html = '<option value="0">请选择医院</option>'
            $.each(data, function (index, item) {
                html += '<option value="' + item.id + '">' + item.name + '</option>'
            });
            dom.html(html);
            form.render("select");
        });

        //模糊查询
        form.on("submit(doSearch)", function (data) {
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });

        //监听工具条的事件
        table.on("toolbar(userTable)", function (obj) {
            switch (obj.event) {
                case 'add':
                    openAddLayer();
                    break;
            }
            ;
        });

        //监听行工具条的事件
        table.on("tool(userTable)", function (obj) {
            var data = obj.data; //获得当前行数据
            switch (obj.event) {
                case 'update':
                    openUpdateUserLayer(data);
                    break;
                case 'delete':
                    deleteUser(data);
                    break;
                case 'resetPwd':
                    resetPwd(data);
                    break
            }
            ;
        });

        var mainIndex;
        var url;

        //打开添加的弹出层
        function openAddLayer() {
            mainIndex = layer.open({
                type: 1,
                content: $("#addOrUpdateDiv"),
                area: ['800px', '600px'],
                title: '添加职工',
                success: function () {
                    $("#dataFrm")[0].reset();

                    url = "/user/addUser";

                }
            });
        }


        //打开修改的弹出层
        function openUpdateUserLayer(data) {
            mainIndex = layer.open({
                type: 1,
                content: $("#addOrUpdateDiv"),
                area: ['800px', '500px'],
                title: '修改职工信息',
                success: function () {
                    $("#dataFrm")[0].reset();
                    //装载新的数据
                    form.val("dataFrm", data);
                    url = "/user/updateUser";
                }
            });
        }

        form.on("submit(doSubmit)", function (data) {
            $.post(url, data.field, function (res) {
                if (res.code == 200) {
                    tableIns.reload();
                }
                layer.msg(res.msg);
                layer.close(mainIndex);
            })
            return false;
        })

        //删除
        function deleteUser(data) {
            layer.confirm('你确定要删除【' + data.name + '】这条用户吗?', {icon: 3, title: '提示'}, function (index) {
                $.post("/user/deleteUser", {id: data.id}, function (res) {
                    if (res.code == 200) {
                        tableIns.reload();
                    }
                    layer.msg(res.msg);
                })
                layer.close(index);
            });
        }


        //重置密码
        function resetPwd(data) {
            layer.confirm('你确定要重置【' + data.name + '】这个用户密码吗?', {icon: 3, title: '提示'}, function (index) {
                $.post("/user/resetPwd", {id: data.id}, function (res) {
                    layer.msg(res.msg);
                })
                layer.close(index);
            });
        }

        //监听用户名的失去焦点事件
        $("#username").on("blur", function () {
            var username = $(this).val();
            $.get("/user/changeChineseToPinyin", {username: username}, function (res) {
                $("#loginname").val(res.value);
            })
        });

    });
</script>

</body>
</html>